2020-2021 Sunseeker Telemetry and Lighting System
gpio_ex2_inputCapture.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // Software Port Interrupt Service on S1 from LPM3 with
34 // Internal Pull-up Resistance Enabled
35 //
36 // A hi "TO" low transition on S1 will trigger P1_ISR/P2_ISR which,
37 // toggles LED1. S1 is internally enabled to pull-up. LPM3 current
38 // can be measured with the LED removed, all
39 // unused Px.x configured as output or inputs pulled high or low.
40 // ACLK = n/a, MCLK = SMCLK = default DCO
41 //
43 // -----------------
44 // /|\| |
45 // | | |
46 // --|RST |
47 // | |
48 // S1-->| |-->LED1
49 //
50 //
51 // This example uses the following peripherals and I/O signals. You must
52 // review these and change as needed for your own board:
53 // - GPIO Port peripheral
54 //
55 // This example uses the following interrupt handlers. To use this example
56 // in your own application you must add these interrupt handlers to your
57 // vector table.
58 // - PORT1_VECTOR/PORT2_VECTOR
59 //******************************************************************************
60 #include "driverlib.h"
61 #include "Board.h"
62 
63 void main (void)
64 {
65  //Stop watchdog timer
66  WDT_A_hold(WDT_A_BASE);
67 
68  //Set LED1 to output direction
69  GPIO_setAsOutputPin(
70  GPIO_PORT_LED1,
71  GPIO_PIN_LED1
72  );
73 
74  //Enable S1 internal resistance as pull-Up resistance
75  GPIO_setAsInputPinWithPullUpResistor(
76  GPIO_PORT_S1,
77  GPIO_PIN_S1
78  );
79 
80  //S1 interrupt enabled
81  GPIO_enableInterrupt(
82  GPIO_PORT_S1,
83  GPIO_PIN_S1
84  );
85 
86  //S1 Hi/Lo edge
87  GPIO_selectInterruptEdge(
88  GPIO_PORT_S1,
89  GPIO_PIN_S1,
90  GPIO_HIGH_TO_LOW_TRANSITION
91  );
92 
93 
94  //S1 IFG cleared
95  GPIO_clearInterrupt(
96  GPIO_PORT_S1,
97  GPIO_PIN_S1
98  );
99 
100  PMM_unlockLPM5();
101 
102  //Enter LPM3 w/interrupt
103  __bis_SR_register(LPM3_bits + GIE);
104 
105  //For debugger
106  __no_operation();
107 }
108 
109 #if GPIO_PORT_S1 == GPIO_PORT_P1
110 //******************************************************************************
111 //
112 //This is the PORT1_VECTOR interrupt vector service routine
113 //
114 //******************************************************************************
115 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
116 #pragma vector=PORT1_VECTOR
117 __interrupt
118 #elif defined(__GNUC__)
119 __attribute__((interrupt(PORT1_VECTOR)))
120 #endif
121 void P1_ISR (void)
122 #elif GPIO_PORT_S1 == GPIO_PORT_P2
123 //******************************************************************************
124 //
125 //This is the PORT2_VECTOR interrupt vector service routine
126 //
127 //******************************************************************************
128 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
129 #pragma vector=PORT2_VECTOR
130 __interrupt
131 #elif defined(__GNUC__)
132 __attribute__((interrupt(PORT2_VECTOR)))
133 #endif
134 void P2_ISR (void)
135 #endif // #if GPIO_PORT_S1
136 {
137  //LED1 = toggle
138  GPIO_toggleOutputOnPin(
139  GPIO_PORT_LED1,
140  GPIO_PIN_LED1
141  );
142 
143  //S1 IFG cleared
144  GPIO_clearInterrupt(
145  GPIO_PORT_S1,
146  GPIO_PIN_S1
147  );
148 }
void main(void)
void P1_ISR(void)
__no_operation()